package com.xianrenit.xianrenpuzi.cart.controller;

import com.xianrenit.xianrenpuzi.cart.service.CartService;
import com.xianrenit.xianrenpuzi.model.entity.h5.CartInfo;
import com.xianrenit.xianrenpuzi.model.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/order/cart")
@Tag(name = "购物车模块")
public class CartController {
    @Resource
    CartService cartService;
    @Operation(summary = "删除购物车选中购物项")
    @DeleteMapping("auth/delCheckedCartInfos")
    public Result delCheckedCartInfos(){
        cartService.delCheckedCartInfos();
        return Result.ok();
    }
    @Operation(summary = "查询用户购物车已选中购物项列表")
    //只要请求头中携带token，不需要再传用户id
    @GetMapping("auth/checkedCartInfos")
    public Result checkedCartInfos(){
        List<CartInfo> cartInfos = cartService.checkedCartInfos();
        return Result.ok(cartInfos);
    }

    @Operation(summary = "全选/全不选")
    @GetMapping("/auth/allCheckCart/{isChecked}")
    public Result allCheckCart(@PathVariable("isChecked")Integer isChecked){
        cartService.allCheckCart(isChecked);
        return Result.ok();
    }
    @Operation(summary = "删除购物车")
    @GetMapping("auth/clearCart")
    public Result clearCart(){
        cartService.clearCart();
        return Result.ok();
    }
    @Operation(summary = "删除指定购物项")
    @DeleteMapping("auth/deleteCart/{skuId}")
    public Result deleteCart(@PathVariable("skuId")Long skuId){
        cartService.deleteCartBySkuId(skuId);
        return Result.ok();
    }
    @Operation(summary = "更新购物项选中状态")
    @GetMapping("auth/checkCart/{skuId}/{isChecked}")
    public Result checkCart(@PathVariable("skuId")Long skuId,
                           @PathVariable("isChecked")Integer isChecked){
        cartService.checkCart(skuId,isChecked);
        return Result.ok();
    }
    @Operation(summary = "查询购物车")
    @GetMapping("auth/cartList")
    public Result cartList(){
        List<CartInfo> cartInfos = cartService.cartList();
        return Result.ok(cartInfos);
    }
    @Operation(summary = "添加商品到购物车")
    @GetMapping("auth/addToCart/{skuId}/{skuNum}")
    public Result addToCart(@PathVariable("skuId")Long skuId,
                            @PathVariable("skuNum")Integer skuNum){
        cartService.addToCart(skuId,skuNum);
        return Result.ok();
    }

}
